#pragma once
#include <memory>
#include <string>
#include <functional>
#include <vector>

// #ifndef BUILD_HPP_STREAM_LIB
// #	ifdef _DEBUG
// #		pragma comment(lib, "HttpStream_d.lib")
// #	else
// #		pragma comment(lib, "HttpStream.lib")
// #	endif
// #endif

//////////////////////////////////////////////////////////////////////////
//
// http://code.google.com/p/http-stream/
// # Non-members may check out a read-only working copy anonymously over HTTP.
// svn checkout http://http-stream.googlecode.com/svn/trunk/ http-stream-read-only
//

class http_stream_impl;

class http_stream
{
public:
	typedef std::tr1::function<void(int,int)>	Progress; // int cur, int total
	typedef std::vector<char>					Bytes;

	http_stream(std::ostream& err_stream, const std::string& server, const std::string& port = "http", size_t trans_bytes_per_once = 1024);
	virtual ~http_stream();

	void										resolve();
	std::istream								responsed_header();
	std::istream								responsed_contents();
	void										set_write_progress( Progress proc );

	http_stream&								operator<<( std::ostream& (*f)(std::ostream&) ); // std::endl, std::flush
	http_stream&								operator<<( const std::string& data );
	http_stream&								operator<<( int data );
	http_stream&								operator<<( const Bytes& bytes );

private:
	std::tr1::shared_ptr< http_stream_impl > impl_;
};

//////////////////////////////////////////////////////////////////////////